package com.dorm.mapper;

import com.dorm.entity.Room;
import com.dorm.entity.Student;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface RoomMapper {
    @Select("SELECT * FROM rooms")
    List<Room> findAll();

    @Select("SELECT * FROM rooms WHERE id = #{id}")
    Room findById(Long id);

    @Select("SELECT * FROM rooms WHERE building_id = #{buildingId}")
    List<Room> findByBuildingId(Long buildingId);

    @Insert("INSERT INTO rooms(room_number, capacity, current_occupancy, building_id) " +
            "VALUES(#{roomNumber}, #{capacity}, #{currentOccupancy}, #{buildingId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Room room);

    @Update("UPDATE rooms SET room_number = #{roomNumber}, " +
            "capacity = #{capacity}, current_occupancy = #{currentOccupancy}, " +
            "building_id = #{buildingId} WHERE id = #{id}")
    int update(Room room);

    @Delete("DELETE FROM rooms WHERE id = #{id}")
    int deleteById(Long id);

    Room findRoomWithStudents(Long id);

    @Select("SELECT COUNT(*) FROM students WHERE room_id = #{roomId}")
    int countStudentsByRoomId(Long roomId);

    @Select("SELECT * FROM students WHERE room_id = #{roomId}")
    List<Student> findStudentsByRoomId(Long roomId);

    @Delete("DELETE FROM hygiene_records WHERE room_id = #{roomId}")
    int deleteHygieneRecords(Long roomId);
} 